package com.imooc.demo.service.impl;

import com.imooc.demo.dao.QkcFavourMapper;
import com.imooc.demo.dao.QkcVideoMapper;
import com.imooc.demo.entity.QkcFavour;
import com.imooc.demo.entity.QkcVideo;
import com.imooc.demo.service.QkcVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by qukoucai001 on 2019/3/14.
 */
@Service
public class QkcVideoServiceImpl implements QkcVideoService {

    @Autowired
    QkcVideoMapper qkcVideoMapper;

    @Autowired
    QkcFavourMapper qkcFavourMapper;


    @Override
    public int deleteByPrimaryKey(Long id) {
        return 0;
    }

    @Override
    public int insert(QkcVideo record) {
        return 0;
    }

    @Override
    public int insertSelective(QkcVideo record) {
        return 0;
    }

    @Override
    public QkcVideo selectByPrimaryKey(Long id) {
        return qkcVideoMapper.selectByPrimaryKey(id);
    }


    @Transactional
    @Override
    public int updateByPrimaryKeySelective(QkcVideo record) {
        try {
            int i = qkcVideoMapper.updateByPrimaryKeySelective(record);
            QkcFavour favour=new QkcFavour();
                      favour.setVideoId(record.getId());
                      favour.setIsRead(0);
                      favour.setOwnerId(record.getUserId());
            int i1 = qkcFavourMapper.insertSelective(favour);
        }catch (Exception e){
            throw new RuntimeException("exception occurs when update operation");
        }
        return 0;
    }

    @Override
    public int updateByPrimaryKey(QkcVideo record) {
        return 0;
    }
}
